package com.reyco1.util
{
	/*
	class
	*/
	
	/**
	 * Utility which allows you to encrypt and decrypt strings using base8 encryption
	 * @author reynaldo.columna
	 * 
	 */	
	public class CryptUtil
	{
		/*
		Generate a random number in range
		*/
		
		/**
		 * Decodes a String
		 * @param $encodedString : String - string to decode
		 * @return : decoded string
		 * 
		 */			
		public static function decode($encodedString:String):String
		{
			var strDecoded:String = new String();
			for (var i:Number = 0; i<$encodedString.length; i += 2) {
				strDecoded += String.fromCharCode(parseInt($encodedString.substr(i, 2), 16));
			}
			return strDecoded;
		}
		
		/**
		 * Encodes a string
		 * @param $str : String - string to be encoded
		 * @return : String - encoded string
		 * 
		 */		
		public static function encode($str:String):String
		{
			var strEncoded:String = new String();;
			for (var i:Number = 0; i<$str.length; i++) {
				strEncoded += $str.charCodeAt(i).toString(16);
			}
			return strEncoded;
		}
	}
}